package com.ruiysoft.crm.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ruiysoft.crm.model.entity.BizClient;
import com.ruiysoft.crm.model.vo.BizClientVo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.Map;

/**
 * @author fanyl
 */
public interface BizClientMapper extends BaseMapper<BizClient> {

    List<BizClient> queryClientAndCarInfo(IPage page, @Param("params") Map<String, Object> params);

    @Select("select client.*,dict.label from biz_client client LEFT JOIN sys_dict dict on client.client_type=dict.value where client.id=#{id}")
    BizClient getClientById(int id);

    @Update("update biz_client set user_id=null,user_name=null,success=null,allocationDate=null where id in (${clientIds })")
    boolean revokeAllotUser(@Param("clientIds") String clientIds);

    @Update("update biz_client set user_id=#{userId },user_name=#{realName },allocationDate=now() where id in (${clientIds })")
    int allocationByBatchid(@Param("batchid") String batchid, @Param("userId") Integer userId, @Param("realName") String realName, @Param("clientIds") String clientIds);


    @Select("select  car_no from biz_client")
    List<String> getCarNos();


    List<BizClientVo> queryClients(@Param("params") Map<String, Object> params);
}
